package chapter6.eg6;

import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * 这是一种错误的用法，因为当前ChannelHandler是需要被多个ChannelPipeline共享的，因而其应该是无状态的
 */
@Sharable
public class UnsharableHandler extends ChannelInboundHandlerAdapter {
  private int count;

  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    count++;
    System.out.println("channelRead(...) called the " + count + " time");
    ctx.fireChannelRead(msg);
  }
}
